﻿Imports System.Net
Imports System.Security.Permissions
Imports System.ServiceModel.Security

Public Class Form1

    Private Sub btnConnect_Click(sender As System.Object, e As System.EventArgs) Handles btnConnect.Click
        Try
            'Net.WebRequest.DefaultWebProxy = New Net.WebProxy("127.0.0.1", 8888)
            Dim siteUrl = New Uri(txtUrl.Text)
            Dim webRequestObj As HttpWebRequest
            webRequestObj = DirectCast(HttpWebRequest.Create(siteUrl), HttpWebRequest)
            webRequestObj.AllowAutoRedirect = True
            webRequestObj.KeepAlive = True
            webRequestObj.AllowWriteStreamBuffering = True
            If Not chkCurrentUser.Checked Then
                webRequestObj.Credentials = New NetworkCredential(txtUsername.Text, txtPassword.Text, "")
            Else
                webRequestObj.Credentials = CredentialCache.DefaultNetworkCredentials
            End If
            Dim Cookies = New CookieContainer()
            webRequestObj.CookieContainer = Cookies

            Dim response As WebResponse = webRequestObj.GetResponse()
            response.Close()


            'Dim siteUrl2 = New Uri("http://haitbalfresco:8080/alfresco/wcs/cmis")
            'Dim webRequestObj As HttpWebRequest
            'webRequestObj = DirectCast(HttpWebRequest.Create(siteUrl2), HttpWebRequest)
            'webRequestObj.AllowAutoRedirect = True
            'webRequestObj.KeepAlive = True

            'webRequestObj.Credentials = New NetworkCredential("administrator", "Kofax123", "")
            'Dim Cookies = New CookieContainer()
            'webRequestObj.CookieContainer = Cookies

            'Dim response As WebResponse = webRequestObj.GetResponse()
            'response.Close()

            MessageBox.Show("Connect successful")
        Catch ex As Exception
            MessageBox.Show("Connect failed: " & ex.Message)
        End Try
    End Sub
End Class
